package com.jiangyg.mall.product.vo;

import com.jiangyg.mall.core.utils.tree.Tree;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 类描述：商品三级分类
 *
 * @author jiangyg
 * @email email@jiangyg.com
 * @date 2021-10-30 07:38:49
 */
@Data
@NoArgsConstructor
@EqualsAndHashCode
public class CategoryVO implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 分类id
     */
    private String id;

    /**
     * 分类名称
     */
    private String name;

    /**
     * 父分类id
     */
    private String pid;

    /**
     * 父级分类名称
     */
    private String pname;

    /**
     * 层级
     */
    private Integer level;

    /**
     * 排序
     */
    private Integer sort;

    /**
     * 图标地址
     */
    private String icon;

    /**
     * 是否显示[0-不显示，1显示]
     */
    private Integer visible;

    /**
     * 功能描述：目录转为菜单
     *
     * @return 菜单
     */
    public Tree toTree() {
        final Tree tree = new Tree();
        tree.setId(this.getId());
        tree.setPid(this.getPid());
        tree.setName(this.getName());
        return tree;
    }

    /**
     * 功能描述：目录转为菜单
     *
     * @return 菜单
     */
    public Tree toMTree() {
        final Tree tree = new Tree();
        tree.setId(this.getId());
        tree.setPid(this.getPid());
        tree.setName(this.getName());
        tree.setSort(this.getSort());
        tree.addAttribute("level", this.getLevel());
        tree.addAttribute("visible", this.getVisible());
        tree.addAttribute("icon", this.getIcon());
        return tree;
    }

}
